<template>
  <div class="record">
    <div class="common">
      <div class="common-input">
        <el-input
          v-model="commonValue"
          placeholder="用户昵称/手机号码"
          clearable
        ></el-input>
      </div>

      <div class="common-input">
        <el-select v-model="commonUpdateValue" placeholder="请选择" clearable>
          <el-option
            v-for="item in commonUpdateOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </div>

      <div class="common-input">
        <el-date-picker
          v-model="commonDate"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
           format="yyyy-MM-dd" value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </div>

      <div class="common-button" @click="searchHit">搜索</div>
      <div class="common-button" @click="replacementHit">重置</div>
    </div>

    <div class="table" v-loading="loading">
      <el-table
        :data="tableData"
        border
        :header-cell-style="{
          color: '#333333',
          backgroundColor: '#f3f3f3',
        }"
      >
        <el-table-column prop="" label="用户头像" align="center" width="150">
          <template slot-scope="scope">
            <img class="imgs" :src="scope.row.avatar" alt="" />
          </template>
        </el-table-column>
        <el-table-column prop="nickname" label="充值用户"> </el-table-column>
        <el-table-column prop="phone" label="充值用户手机号"> </el-table-column>
        <el-table-column prop="price" label="充值金额（元）"> </el-table-column>
        <el-table-column prop="" label="充值方式" width="200">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.type == 'WX'" type="success">微信</el-tag>
            <el-tag v-if="scope.row.type == 'ZFB'">支付宝</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="充值时间"> </el-table-column>
        <!-- <el-table-column fixed="right" label="操作" width="200">
          <template slot-scope="scope">
            <div class="operation">
              <div class="list" @click.prevent="deleteHit(scope.row)">删除</div>
            </div>
          </template>
        </el-table-column> -->
      </el-table>

      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          layout="prev, pager, next"
          :total="tableDataTotal"
          :current-page="page"
        >
        </el-pagination>
      </div>
    </div>

    <!--处理弹出框-->
    <div class="official">
      <el-dialog
        title="删除"
        :visible.sync="deleteVisible"
        :before-close="deleteClose"
        round
      >
        <div class="official-title">是否确认删除？</div>
        <div class="official-attachment">
          <div class="list" @click="deleteClose">取消</div>
          <div class="list" @click="deleteConfirm">确定</div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { rechargeLogList } from "@/api/recharge";
export default {
  data() {
    return {
      commonValue: "",
      commonUpdateOptions: [
        {
          value: "wx",
          label: "微信",
        },
        {
          value: "ZFB",
          label: "支付宝",
        },
      ],
      commonUpdateValue: "",
      commonDate: [],
      commonStart: "",
      commonEnd: "",
      //-------------
      page: 1,
      limit: 10,
      tableData: [],
      tableDataTotal: 0,
      loading: false,
      commonObj: {},
      //------------
      deleteVisible: false,
    };
  },
  created() {
    this.loading = true;
    this.recordFeedbackListMet();
  },
  methods: {
    recordFeedbackListMet() {
      let params = {
        keyWord: this.commonValue,
        startTime: this.commonStart,
        endTime: this.commonEnd,
        type: this.commonUpdateValue,
        //------
        pageSize: this.limit,
        pageNo: this.page,
      };

      rechargeLogList(params).then((res) => {
        if (res.errorCode == null) {
          res.resultData.userRechargeList.forEach((item, index) => {
            item.price = Number(item.price / 100).toFixed(2);
          });

          this.tableData = res.resultData.userRechargeList;
          this.tableDataTotal = res.resultData.totalNum;
          this.loading = false;
        }
      });
    },
    timeData(date) {
      return date.toLocaleString("zh-CN", {
        year: "numeric",
        month: "2-digit",
        day: "2-digit",
      });
    },
    searchHit() {
      if (this.commonDate.length > 0) {
        this.commonStart = this.timeData(new Date(this.commonDate[0]));
        this.commonEnd = this.timeData(new Date(this.commonDate[1]));
      } else {
        this.commonStart = "";
        this.commonEnd = "";
      }

      this.page = 1;
      this.loading = true;
      this.recordFeedbackListMet();
    },
    replacementHit() {
      this.commonDate = [];
      this.commonStart = "";
      this.commonEnd = "";
      this.commonValue = "";

      this.commonUpdateValue = "";

      this.page = 1;
      this.loading = true;
      this.recordFeedbackListMet();
    },
    //-------------------------
    deleteHit(item) {
      if (this.$store.state.premissions.infoRouterShow == false) {
        this.$message.error("暂无权限，请联系管理员开通");
        return;
      }
      this.commonObj = item;
      this.deleteVisible = true;
    },
    deleteClose() {
      this.deleteVisible = false;
    },
    deleteConfirm() {
      let params = this.commonObj.feedbackId;

      // recordFeedbackListIdPut(params).then((res) => {
      //   if (res.errorCode == null) {
      //     this.$message.success("处理成功！");
      //     this.loading = true;
      //     this.page = 1;
      //     this.recordFeedbackListMet();
      //     this.deleteVisible = false;
      //   }
      // });
    },

    //---------
    handleSizeChange(val) {
      this.limit = val;
      this.loading = true;
      this.recordFeedbackListMet();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.loading = true;
      this.recordFeedbackListMet();
    },
  },
};
</script>

<style lang="less" scoped>
@import url("@/assets/css/official.less");

.record {
  .common {
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    .common-input {
      margin-right: 10px;
      /deep/ .el-input {
        width: 250px;
      }
    }

    .common-input:last-child {
      margin-right: 0;
    }

    .common-button {
      padding: 9px 20px;
      box-sizing: border-box;
      border-radius: 5px;
      background: #2a82e4;
      font-size: 14px;
      color: #fff;
      margin-left: 20px;
      cursor: pointer;
    }

    .common-button:last-child {
      background: #999999;
    }
  }

  .table {
    cursor: pointer;

    .operation {
      display: flex;
      align-items: center;
      color: #2a82e4;

      .list {
        margin-right: 20px;
        cursor: pointer;
      }
    }

    .imgs {
      width: 50px;
      height: 50px;
    }
  }
}
</style>